package com.jd.cmdb.tsc.controller;

import com.jd.cmdb.tsc.entity.Task;
import com.jd.cmdb.tsc.service.TaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by tianzhengguo on 2016/1/13.
 */
@Controller
@RequestMapping("/task")
public class TaskController {

    private static final Logger logger = LoggerFactory.getLogger(TaskController.class);

    @Resource
    private TaskService taskService;

    @RequestMapping
    public String home(){
        return "task";
    }

    @ResponseBody
    @RequestMapping("/listAll")
    public List<Task> listAll(){
        List<Task> taskList = new ArrayList<>();
        try {
            taskList = taskService.selAllTasks();
//            Map<String,List<Task>> taskMap = new HashMap<String,List<Task>>();
//            taskMap.put("taskList",taskList);
//            modelAndView = new ModelAndView("task",taskMap);
        }catch (Exception e){
            logger.error("发生异常:{}", e.getMessage());
//            modelAndView.setView();
//            modelAndView = new ModelAndView("500");
        }
        return taskList;
    }
}
